% 参数初始化
numInputs = 4;          % 输入层节点数
numMFsPerInput = 2;     % 每个输入的隶属度函数数
numRules = numMFsPerInput ^ numInputs;  % 模糊规则数
numOutputs = 2;         % 输出层节点数

% 随机初始化权重
%W = rand(numOutputs, 1 + numInputs^numMFsPerInput);

% 输入向量
%S = [dg, do, theta_g, theta_o];  % 假设的输入向量
S=[5,1,pi/3,-pi/6];%假设值

%设置权重
a_initial%导入权重a
W=a_initial*sum(S(:));

%文献均值和标准差
c=[0,0,-pi/2,-pi/2;
    10,5,pi/2,pi/2];
sigma=[2.5,1,1,1];
% 隶属度层
MFs = zeros(numMFsPerInput, numInputs);
for i = 1:numInputs
    for j = 1:numMFsPerInput
        % 定义高斯隶属度函数的参数
        c_ij= c(j,i);%均值
        sigma_ij= sigma(i);%标准差
        MFs(j, i) = exp(-((S(i)-c_ij)^2)/(sigma_ij^2));
    end
end
% 
% % 模糊规则层
firingStrengths = ones(1, numRules);
for r = 1:numRules
    % 计算每条规则的激活程度（AND操作）
    switch r
        case 1
            firingStrengths(r)=MFs(1,1)*MFs(1,2)*MFs(1,3)*MFs(1,4);
        case 2
            firingStrengths(r)=MFs(1,1)*MFs(1,2)*MFs(1,3)*MFs(2,4);
        case 3
            firingStrengths(r)=MFs(1,1)*MFs(1,2)*MFs(2,3)*MFs(2,4);
        case 4
            firingStrengths(r)=MFs(1,1)*MFs(2,2)*MFs(2,3)*MFs(1,4);
        case 5
            firingStrengths(r)=MFs(1,1)*MFs(2,2)*MFs(1,3)*MFs(1,4);
        case 6
            firingStrengths(r)=MFs(1,1)*MFs(2,2)*MFs(1,3)*MFs(2,4);
        case 7
            firingStrengths(r)=MFs(1,1)*MFs(2,2)*MFs(2,3)*MFs(2,4);
        case 8
            firingStrengths(r)=MFs(1,1)*MFs(2,2)*MFs(2,3)*MFs(1,4);
        case 9
            firingStrengths(r)=MFs(2,1)*MFs(2,2)*MFs(1,3)*MFs(1,4);
        case 10
            firingStrengths(r)=MFs(2,1)*MFs(2,2)*MFs(1,3)*MFs(2,4);
        case 11
            firingStrengths(r)=MFs(2,1)*MFs(2,2)*MFs(2,3)*MFs(2,4);
        case 12
            firingStrengths(r)=MFs(2,1)*MFs(2,2)*MFs(2,3)*MFs(1,4);
        case 13
            firingStrengths(r)=MFs(2,1)*MFs(1,2)*MFs(1,3)*MFs(1,4);
        case 14
            firingStrengths(r)=MFs(2,1)*MFs(1,2)*MFs(1,3)*MFs(2,4);
        case 15
            firingStrengths(r)=MFs(2,1)*MFs(1,2)*MFs(2,3)*MFs(2,4);
        case 16
            firingStrengths(r)=MFs(2,1)*MFs(1,2)*MFs(2,3)*MFs(1,4);
    end
end

pre_firingStrengths=zeros(1,numRules);
time_delay=zeros(1,numRules);
now_firingStrengths=(ones(1,numRules)-time_delay).*firingStrengths+time_delay.*pre_firingStrengths;

% 后件层和输出层
Outputs = zeros(numOutputs, 1);
for o = 1:numOutputs
    for r = 1:numRules
        % 线性组合（示例）
        Outputs(o) = Outputs(o) + now_firingStrengths(r) * W(o, r);
    end
    % 激活函数（示例）
    %Outputs(o) = tanh(Outputs(o));
end